package com.ktgj.pay.utils;

import org.bouncycastle.util.encoders.Base64;

import java.io.*;


/**
 * PDF转换工具类
 * @author Maming
 *
 */
public class GetPDFFileUtil {
	/**
     * @Description:Base64转换成pdf
     * @param:pdfbase64编码、存储指向路径
     * @return:
     * @author: Maming
     * @Date: 2019/10/09
     */
    public static void BasetoPdffile(String pdfBase64Str,String filepath){
        BufferedInputStream bis = null;
        FileOutputStream fos = null;
        BufferedOutputStream bos = null;
        try{
            byte[] bytes=Base64.decode(pdfBase64Str);
            ByteArrayInputStream byteArrayInputStream=new ByteArrayInputStream(bytes);
            bis=new BufferedInputStream(byteArrayInputStream);
            File file=new File(filepath);
            File path=file.getParentFile();
            if(!path.exists()){
                path.mkdirs();
            }
            fos=new FileOutputStream(file);
            bos=new BufferedOutputStream(fos);
 
            byte[] buffer=new byte[1024];
            int length=bis.read(buffer);
            while(length!=-1){
                bos.write(buffer,0,length);
                length=bis.read(buffer);
            }
            bos.flush();
        }catch(Exception e){
        e.printStackTrace();
        }finally {
            try{
                bis.close();
                bos.close();
                fos.close();
            }catch (IOException e){
                e.printStackTrace();
            }
        }
    }
	
}
